Home:ALL Converter>How to change the url of an app in Django to custom url

How to change the url of an app in Django to custom url

Ask Time:2021-07-29T15:20:25         Author:RlM

Json Formatter

I have an app in my Django project that called Stressz. So the url of my app is:

http://localhost:8000/stressz/
http://localhost:8000/stressz/siker
http://localhost:8000/stressz/attitud

How can I change the url without changing the name of the app from the above url to something like this:

http://localhost:8000/mpa
http://localhost:8000/mpa/siker
http://localhost:8000/mpa/attitud

urls.py

app_name = 'stressz'
urlpatterns = [
    path('', views.index, name='index'),
    path('siker', views.siker, name='siker'),
    path('attitud', login_required(views.AttitudCreateView.as_view()), name='attitud_item'),
    ...

Author:RlM,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/68571707/how-to-change-the-url-of-an-app-in-django-to-custom-url
dustin-we :

Look into your root urls.py, which you can usually find in your project (not app) folder. There has to be a line similar to this:\nurlpatterns = [\n path('stressz', include('stressz.urls')),\n]\n\nIf you then change it to:\nurlpatterns = [\n path('mpa', include('stressz.urls')),\n]\n\nIt should work as you intended.",
2021-07-29T07:37:01
yy